﻿<UserControl x:Class="SEToolbox.Views.ControlCubeGrid"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:converters="clr-namespace:SEToolbox.Converters"
             xmlns:controls="clr-namespace:SEToolbox.Controls"
             xmlns:commands="clr-namespace:SEToolbox.Services"
             xmlns:views="clr-namespace:SEToolbox.Views"
             xmlns:s="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="600"
             commands:DialogService.IsRegisteredView="True">
    <UserControl.Resources>
        <converters:EnumToResouceConverter x:Key="EnumToResouceConverter"/>
        <converters:ResouceToImageConverter x:Key="ResouceToImageConverter"/>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <converters:DDSConverter x:Key="DDSConverter"/>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </UserControl.Resources>

    <Grid>
        <TabControl>
            <TabItem Header="{Binding ClassType, Converter={StaticResource EnumToResouceConverter}}">
                <DockPanel>
                    <Menu DockPanel.Dock="Top">
                        <Menu.ItemsPanel>
                            <ItemsPanelTemplate>
                                <DockPanel HorizontalAlignment="Stretch" Height="22"/>
                            </ItemsPanelTemplate>
                        </Menu.ItemsPanel>
                        <MenuItem Header="Repair" Command="{Binding RepairObjectCommand}" Style="{StaticResource ToolBarTopMenuitem}">
                            <MenuItem.Icon>
                                <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=wrench}" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="Speed" Style="{StaticResource ToolBarTopMenuitem}">
                            <MenuItem.Icon>
                                <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=speedometer}" />
                            </MenuItem.Icon>
                            <MenuItem Header="Reset Linear Velocity" Command="{Binding ResetLinearVelocityCommand}" ToolTip="Set Linear Velocity to zero (0).">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=media_stop}" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Reset Rotation Velocity" Command="{Binding ResetRotationVelocityCommand}" ToolTip="Set Rotation Velocity to zero (0).">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=media_stop}" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Reset all Speed" Command="{Binding ResetVelocityCommand}" ToolTip="Set Linear and Rotation Velocity to zero (0).">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=media_stop}" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Reverse Speed" Command="{Binding ReverseVelocityCommand}" ToolTip="Reverse Linear and Rotation Velocity, sending objects back in the opposite direction and spin.">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=navigate_left2}" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Max Speed At Player" Command="{Binding MaxVelocityAtPlayerCommand}" ToolTip="Sets the object velocity directly at the player at maximum speed.">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=navigate_right2}" />
                                </MenuItem.Icon>
                            </MenuItem>
                        </MenuItem>
                        <MenuItem Header="Convert" Command="{Binding ConvertCommand}" Style="{StaticResource ToolBarTopMenuitem}">
                            <MenuItem.Icon>
                                <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=transform}" />
                            </MenuItem.Icon>
                            <MenuItem Header="Armor">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=shield}" />
                                </MenuItem.Icon>
                                <MenuItem Header="To Heavy Armor" Command="{Binding ConvertToHeavyArmorCommand}" ToolTip="Convert any Light armor blocks to Heavy Armor blocks."/>
                                <MenuItem Header="To Light Armor" Command="{Binding ConvertToLightArmorCommand}" ToolTip="Convert any Heavy armor block to Light armor blocks."/>
                                <Separator/>
                                <MenuItem Header="To Corner Armor" Command="{Binding ConvertToCornerArmorCommand}" ToolTip="Convert any Round armor edge blocks to Corner armor edge blocks."/>
                                <MenuItem Header="To Round Armor" Command="{Binding ConvertToRoundArmorCommand}" ToolTip="Convert any Corner armor edge blocks to Round armor edge blocks."/>
                            </MenuItem>
                            <MenuItem Header="Framework" Command="{Binding FrameworkCommand}">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=cube_molecule}" />
                                </MenuItem.Icon>
                                <MenuItem Header="To 0.5% Framework" Command="{Binding ConvertToFrameworkCommand}" ToolTip="Any constructed components are unconstructed.">
                                    <MenuItem.CommandParameter>
                                        <s:Double>0.005</s:Double>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                                <MenuItem Header="To 25% Framework" Command="{Binding ConvertToFrameworkCommand}" ToolTip="All components are set to a 25% constructed state.">
                                    <MenuItem.CommandParameter>
                                        <s:Double>0.25</s:Double>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                                <MenuItem Header="To 50% Framework" Command="{Binding ConvertToFrameworkCommand}" ToolTip="All components are set to a 50% constructed state.">
                                    <MenuItem.CommandParameter>
                                        <s:Double>0.50</s:Double>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                                <MenuItem Header="To 75% Framework" Command="{Binding ConvertToFrameworkCommand}" ToolTip="All components are set to a 75% constructed state.">
                                    <MenuItem.CommandParameter>
                                        <s:Double>0.75</s:Double>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                                <MenuItem Header="To 100% Complete Structure" Command="{Binding ConvertToFrameworkCommand}" ToolTip="Any unconstructed components are 100% constructed.">
                                    <MenuItem.CommandParameter>
                                        <s:Double>1.00</s:Double>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                            </MenuItem>
                            <MenuItem Header="Station/Ship">
                                <MenuItem Header="To Ship" Command="{Binding ConvertToShipCommand}" ToolTip="Change a Station into a Large Ship." />
                                <MenuItem Header="To Station" Command="{Binding ConvertToStationCommand}" ToolTip="Change a Large Ship into a Station." />
                            </MenuItem>
                            <MenuItem Header="Rotate">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=replace2}" />
                                </MenuItem.Icon>
                                <MenuItem Header="Reorient Station to Axis" Command="{Binding ReorientStationCommand}" ToolTip="Reorients to the accepted single orientation for a Station, and corrects the position to match standard Space Engineers block locations." />
                                <Separator/>
                                <!--<MenuItem Header="Rotate structure backward-down around X axis (+90 Pitch)" Command="{Binding RotateStructurePitchPositiveCommand}"/>
                                <MenuItem Header="Rotate structure forward-down around X axis (-90 Pitch)" Command="{Binding RotateStructurePitchNegativeCommand}"/>
                                <MenuItem Header="Rotate structure anti-clockwise around Y axis (+90 Yaw)" Command="{Binding RotateStructureYawPositiveCommand}"/>
                                <MenuItem Header="Rotate structure clockwise around Y axis (-90 Yaw)" Command="{Binding RotateStructureYawNegativeCommand}"/>
                                <MenuItem Header="Rotate structure left-down around Z axis (+90 Roll)" Command="{Binding RotateStructureRollPositiveCommand}"/>
                                <MenuItem Header="Rotate structure right-down around Z axis (-90 Roll)" Command="{Binding RotateStructureRollNegativeCommand}"/>
                                <Separator/>-->
                                <MenuItem Header="Rotate cubes backward-down around X axis (+90 Pitch)" Command="{Binding RotateCubesPitchPositiveCommand}"/>
                                <MenuItem Header="Rotate cubes forward-down around X axis (-90 Pitch)" Command="{Binding RotateCubesPitchNegativeCommand}"/>
                                <MenuItem Header="Rotate cubes anti-clockwise around Y axis (+90 Yaw)" Command="{Binding RotateCubesYawPositiveCommand}"/>
                                <MenuItem Header="Rotate cubes clockwise around Y axis (-90 Yaw)" Command="{Binding RotateCubesYawNegativeCommand}"/>
                                <MenuItem Header="Rotate cubes left-down around Z axis (+90 Roll)" Command="{Binding RotateCubesRollPositiveCommand}"/>
                                <MenuItem Header="Rotate cubes right-down around Z axis (-90 Roll)" Command="{Binding RotateCubesRollNegativeCommand}"/>
                            </MenuItem>
                            <!--<MenuItem Header="Ladder to Passage" Command="{Binding ConvertLadderToPassageCommand}"/>-->
                        </MenuItem>
                        <MenuItem Header="Mirror">
                            <MenuItem Header="Using predefined X/Y/Z Symmetry Planes" Command="{Binding MirrorStructureByPlaneCommand}" ToolTip="Uses planes as defined on the ship/station within Space Engineers." />
                            <MenuItem Header="Find largest surface / odd [left&gt;|center|&lt;right]" Command="{Binding MirrorStructureGuessOddCommand}" ToolTip="Finds the single largest surface on the edge, and mirrors from there."/>
                            <MenuItem Header="Find largest surface / even [left&gt;|&lt;right]" Command="{Binding MirrorStructureGuessEvenCommand}" ToolTip="Finds the single largest surface on the edge, and mirrors from there."/>
                        </MenuItem>
                        <MenuItem Header="Optimize" Command="{Binding OptimizeObjectCommand}" Style="{StaticResource ToolBarTopMenuitem}" ToolTip="Only useful for enormous ships of more than 200,000 blocks. Reorganises order of cubes within the file, to speed up loading time.">
                            <MenuItem.Icon>
                                <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=sort_descending}" />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem HorizontalAlignment="Right" Style="{StaticResource ToolBarTopMenuitem}" ToolTip="Copy text detail to Clipboard" Command="{Binding CopyDetailCommand}">
                            <MenuItem.Icon>
                                <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=copy}" />
                            </MenuItem.Icon>
                        </MenuItem>
                    </Menu>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="1" Grid.Column="0" Content="Name:"/>
                        <TextBox Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Text="{Binding DisplayName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        <Label Grid.Row="2" Grid.Column="0" Content="Dampeners:"/>
                        <CheckBox Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" IsChecked="{Binding Dampeners, Mode=TwoWay}" />
                        <Label Grid.Row="3" Grid.Column="0" Content="Destructible:"/>
                        <CheckBox Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" IsChecked="{Binding Destructible, Mode=TwoWay}" />
                        <Label Grid.Row="4" Grid.Column="0" Content="Position:"/>
                        <views:ControlPosition Grid.Row="4" Grid.Column="1"/>

                        <Button Grid.Column="0" Grid.Row="5" Margin="4 0 4 0" HorizontalAlignment="Left" Content="Damage:" Style="{StaticResource DropDownMenuButton}">
                            <i:Interaction.Behaviors>
                                <commands:ButtonDropDownMenuBehavior />
                            </i:Interaction.Behaviors>
                            <Button.ContextMenu>
                                <ContextMenu HorizontalAlignment="Right">
                                    <MenuItem Header="Repair" Command="{Binding RepairObjectCommand}" Style="{StaticResource ToolBarTopMenuitem}">
                                        <MenuItem.Icon>
                                            <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=wrench}" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                </ContextMenu>
                            </Button.ContextMenu>
                        </Button>

                        <TextBlock Grid.Row="5" Grid.Column="1" VerticalAlignment="Center" Text="{Binding DamageCount}" />

                        <Button Grid.Column="0" Grid.Row="6" Margin="4 0 4 0" HorizontalAlignment="Left" Content="Speed:" Style="{StaticResource DropDownMenuButton}">
                            <i:Interaction.Behaviors>
                                <commands:ButtonDropDownMenuBehavior />
                            </i:Interaction.Behaviors>
                            <Button.ContextMenu>
                                <ContextMenu HorizontalAlignment="Right">
                                    <MenuItem Header="Reset Linear Velocity" Command="{Binding ResetLinearVelocityCommand}" ToolTip="Set Linear Velocity to zero (0).">
                                        <MenuItem.Icon>
                                            <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=media_stop}" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Header="Reset Rotation Velocity" Command="{Binding ResetRotationVelocityCommand}" ToolTip="Set Rotation Velocity to zero (0).">
                                        <MenuItem.Icon>
                                            <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=media_stop}" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Header="Reset all Speed" Command="{Binding ResetVelocityCommand}" ToolTip="Set Linear and Rotation Velocity to zero (0).">
                                        <MenuItem.Icon>
                                            <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=media_stop}" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Header="Reverse Speed" Command="{Binding ReverseVelocityCommand}" ToolTip="Reverse Linear and Rotation Velocity, sending objects back in the opposite direction and spin.">
                                        <MenuItem.Icon>
                                            <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=navigate_left2}" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Header="Max Speed At Player" Command="{Binding MaxVelocityAtPlayerCommand}" ToolTip="Sets the object velocity directly at the player at maximum speed.">
                                        <MenuItem.Icon>
                                            <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=navigate_right2}" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                </ContextMenu>
                            </Button.ContextMenu>
                        </Button>
                        <Grid Grid.Row="6" Grid.Column="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" VerticalAlignment="Center" Text="{Binding LinearVelocity, StringFormat='{}{0:#,###0.000} m/s'}" ToolTip="Linear Velocity" />
                            <TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding AngularVelocity, StringFormat='{}{0:#,###0.000} m/s'}" ToolTip="Approximate Angular Velocity" Margin="8,0,0,0" />
                        </Grid>
                        <Separator Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2"/>
                        <TextBlock Grid.Row="8" Grid.Column="0" Margin="4 0 4 0" Text="Piloted:"/>
                        <TextBlock Grid.Row="8" Grid.Column="1" VerticalAlignment="Center" Text="{Binding IsPiloted}" />
                        <TextBlock Grid.Row="9" Grid.Column="0" Margin="4 0 4 0" Text="Distance:"/>
                        <TextBlock Grid.Row="9" Grid.Column="1" VerticalAlignment="Center" Text="{Binding PlayerDistance, StringFormat='{}{0:#,###0.0} m'}" />
                        <TextBlock Grid.Row="10" Grid.Column="0" Margin="4 0 4 0" Text="Scale:"/>
                        <TextBlock Grid.Row="10" Grid.Column="1" VerticalAlignment="Center">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} × {1} × {2} blocks">
                                    <Binding Path="Scale.X" />
                                    <Binding Path="Scale.Y" />
                                    <Binding Path="Scale.Z" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBlock Grid.Row="11" Grid.Column="0" Margin="4 0 4 0" Text="Size:"/>
                        <TextBlock Grid.Row="11" Grid.Column="1" VerticalAlignment="Center">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0}m × {1}m × {2}m">
                                    <Binding Path="Size.Width" />
                                    <Binding Path="Size.Height" />
                                    <Binding Path="Size.Depth" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBlock Grid.Row="12" Grid.Column="0" Margin="4 0 4 0" Text="Center:"/>
                        <TextBlock Grid.Row="12" Grid.Column="1" VerticalAlignment="Center">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0:#,##0.0000}, {1:#,##0.0000}, {2:#,##0.0000}">
                                    <Binding Path="Center.X" />
                                    <Binding Path="Center.Y" />
                                    <Binding Path="Center.Z" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBlock Grid.Row="13" Grid.Column="0" Margin="4 0 4 0" Text="Mass:"/>
                        <TextBlock Grid.Row="13" Grid.Column="1" VerticalAlignment="Center" Text="{Binding Mass, StringFormat='{}{0:#,###0.00} Kg'}" />
                        <TextBlock Grid.Row="14" Grid.Column="0" Margin="4 0 4 0" Text="Blocks:"/>
                        <TextBlock Grid.Row="14" Grid.Column="1" VerticalAlignment="Center" Text="{Binding BlockCount, StringFormat='{}{0:#,###0}'}" />
                        <TextBlock Grid.Row="15" Grid.Column="0" Margin="4 0 4 0" Text="Cockpit Orientation:"/>
                        <TextBlock Grid.Row="15" Grid.Column="1" VerticalAlignment="Center" Text="{Binding CockpitOrientation}" />
                    </Grid>
                </DockPanel>
            </TabItem>
            <TabItem Header="Cubes">
                <Grid>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Margin="4 0 4 0" Text="Filter:" VerticalAlignment="Center"/>
                            <TextBox Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,0,4,0" Text="{Binding ComponentFilter, UpdateSourceTrigger=PropertyChanged}" ToolTip="Enter the name of cube to filter by.">
                                <TextBox.InputBindings>
                                    <KeyBinding Key="Enter" Command="{Binding FilterStartCommand}"/>
                                    <KeyBinding Key="Tab" Command="{Binding FilterTabStartCommand}"/>
                                    <KeyBinding Key="Escape" Command="{Binding FilterClearCommand}"/>
                                </TextBox.InputBindings>
                            </TextBox>
                            <Button Grid.Column="2" ToolTip="Search (Enter)" Command="{Binding FilterStartCommand}" IsTabStop="False">
                                <Button.Content>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=find}" />
                                </Button.Content>
                            </Button>
                            <Button Grid.Column="3" ToolTip="Clear Filter (Esc)" Command="{Binding FilterClearCommand}" IsTabStop="False">
                                <Button.Content>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=navigate_cross}" />
                                </Button.Content>
                            </Button>
                        </Grid>
                        <Menu Grid.Row="1" Grid.ColumnSpan="2">
                            <MenuItem Command="{Binding DeleteCubesCommand}" Header="Delete" Style="{StaticResource ToolBarTopMenuitem}">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=delete2}"/>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Command="{Binding ReplaceCubesCommand}" Header="Replace" Style="{StaticResource ToolBarTopMenuitem}">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=selection_replace}"/>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Command="{Binding ColorCubesCommand}" Header="Color" Style="{StaticResource ToolBarTopMenuitem}">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=colors}"/>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Command="{Binding FrameworkCubesCommand}" Header="Framework" Style="{StaticResource ToolBarTopMenuitem}">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=cube_molecule}"/>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Command="{Binding SetOwnerCommand}" Header="Owner" Style="{StaticResource ToolBarTopMenuitem}">
                                <MenuItem.Icon>
                                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=users_back}"/>
                                </MenuItem.Icon>
                            </MenuItem>
                        </Menu>
                        <Grid Grid.Row="2">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="2*" MinHeight="100"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*" MinHeight="100"/>
                            </Grid.RowDefinitions>
                            <controls:SortableListView Grid.Row="0" ItemsSource="{Binding CubeList, Mode=OneWay}"
                            ColumnHeaderArrowUpTemplate="{StaticResource HeaderTemplateArrowUp}" ColumnHeaderArrowDownTemplate="{StaticResource HeaderTemplateArrowDown}" SelectedValue="{Binding SelectedCubeItem}">
                                <ListView.View>
                                    <GridView>
                                        <controls:SortableGridViewColumn Width="30" Header="Icon" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Width="16" Height="16" Source="{Binding Path=TextureFile, Converter={StaticResource DDSConverter}, ConverterParameter='16,16'}" SnapsToDevicePixels="True" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Width="30" Header="Color">
                                            <controls:SortableGridViewColumn.SortBinding>
                                                <MultiBinding>
                                                    <Binding Path="ColorHue" />
                                                    <Binding Path="ColorSaturation" />
                                                    <Binding Path="ColorLuminance" />
                                                </MultiBinding>
                                            </controls:SortableGridViewColumn.SortBinding>
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Border Width="16" Height="16" Background="{Binding Color}" BorderBrush="Black" BorderThickness="1"  ToolTip="{Binding ColorText}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Build" Width="60" SortBinding="{Binding BuildPercent}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=BuildPercent, StringFormat='P'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="X" Width="40" SortBinding="{Binding Position.X}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Position.X}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Y" Width="40" SortBinding="{Binding Position.Y}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Position.Y}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Z" Width="40" SortBinding="{Binding Position.Z}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Position.Z}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Name" Width="175" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding FriendlyName, Converter={StaticResource EnumToResouceConverter}}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <GridViewColumn Header="Owner" Width="80">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding OwnerName, Converter={StaticResource EnumToResouceConverter}}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </GridViewColumn>
                                    </GridView>
                                </ListView.View>
                                <ListView.InputBindings>
                                    <KeyBinding Key="Delete" Command="{Binding DeleteCubesCommand}" />
                                </ListView.InputBindings>
                                <i:Interaction.Behaviors>
                                    <!-- This custom behavior that synchronizes the selected items with the view models collection -->
                                    <commands:SynchronizeSelectedItems Selections="{Binding Selections}"/>
                                </i:Interaction.Behaviors>
                            </controls:SortableListView>
                            <GridSplitter Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Height="4" />

                            <!-- TODO: May have to move all this to a dialog, as parsing and setting up the information takes time. -->
                            <TabControl Grid.Row="2">
                                <!-- TODO: Create DataTemplate to properly show controls and inventories.  -->
                                <!--<TabItem Header="Controls">
                                    --><!-- TODO: Property Editor? --><!--
                                </TabItem>-->
                                <TabItem Header="{Binding Path=SelectedCubeItem.Inventory[0].Name}" Visibility="{Binding Path=SelectedCubeItem.Inventory[0].IsValid, Converter={StaticResource BooleanToVisibilityConverter}}">
                                    <views:ControlInventory DataContext="{Binding Path=SelectedCubeItem.Inventory[0]}" />
                                </TabItem>
                                <TabItem Header="{Binding Path=SelectedCubeItem.Inventory[1].Name}" Visibility="{Binding Path=SelectedCubeItem.Inventory[1].IsValid, Converter={StaticResource BooleanToVisibilityConverter}}">
                                    <views:ControlInventory DataContext="{Binding Path=SelectedCubeItem.Inventory[1]}" />
                                </TabItem>
                            </TabControl>
                            <StackPanel Grid.Row="2">
                                <!--<TextBlock Text="Preview" FontSize="20" Foreground="#80808080" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,-20,0" IsHitTestVisible="False">
                                    <TextBlock.RenderTransform>
                                        <RotateTransform Angle="45"/>
                                    </TextBlock.RenderTransform>
                                </TextBlock>-->
                            </StackPanel>
                        </Grid>
                    </Grid>
                  
                    <controls:BusyIndicator Visibility="{Binding IsSubsSystemNotReady, Converter={StaticResource BooleanToVisibilityConverter}}" />
                </Grid>
            </TabItem>
            <TabItem Header="Construction">
                <Grid>
                    <ScrollViewer>
                        <Grid>
                            <i:Interaction.Behaviors>
                                <commands:BubbleScrollBehavior />
                            </i:Interaction.Behaviors>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Grid.Column="0" Margin="4 0 4 0" Text="Total time to produce:"/>
                            <TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding TimeToProduce, StringFormat='{}{0:dd} days, {0:hh} hours, {0:mm\\:ss\\.ff}'}"/>
                            <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"/>
                            <controls:SortableListView Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding CubeAssets}"
                        ColumnHeaderArrowUpTemplate="{StaticResource HeaderTemplateArrowUp}" ColumnHeaderArrowDownTemplate="{StaticResource HeaderTemplateArrowDown}">
                                <ListView.View>
                                    <GridView>
                                        <controls:SortableGridViewColumn Width="44" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Width="32" Height="32" Source="{Binding Path=TextureFile, Converter={StaticResource DDSConverter}, ConverterParameter='32,32'}" SnapsToDevicePixels="True" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Cubes" Width="175" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding FriendlyName, Converter={StaticResource EnumToResouceConverter}}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Count" Width="80" SortBinding="{Binding Count}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Count, StringFormat='{}{0:#,##0}'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Mass" Width="100" SortBinding="{Binding Mass}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Mass, StringFormat='{}{0:#,##0.00} Kg'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Time" Width="90" SortBinding="{Binding Time}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Time, StringFormat='{}{0:hh\\:mm\\:ss\\.ff}'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                    </GridView>
                                </ListView.View>
                            </controls:SortableListView>
                            <controls:SortableListView Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding ComponentAssets}"
                    ColumnHeaderArrowUpTemplate="{StaticResource HeaderTemplateArrowUp}" ColumnHeaderArrowDownTemplate="{StaticResource HeaderTemplateArrowDown}">
                                <ListView.View>
                                    <GridView>
                                        <controls:SortableGridViewColumn Width="44" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Width="32" Height="32" Source="{Binding Path=TextureFile, Converter={StaticResource DDSConverter}, ConverterParameter='32,32'}" SnapsToDevicePixels="True" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Components" Width="175" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding FriendlyName, Converter={StaticResource EnumToResouceConverter}}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Count" Width="80" SortBinding="{Binding Count}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Count, StringFormat='{}{0:#,##0}'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Mass" Width="100" SortBinding="{Binding Mass}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Mass, StringFormat='{}{0:#,##0.00} Kg'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Volume" Width="90" SortBinding="{Binding Volume}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Volume, StringFormat='{}{0:#,##0.00} L'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Time" Width="90" SortBinding="{Binding Time}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Time, StringFormat='{}{0:hh\\:mm\\:ss\\.ff}'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                    </GridView>
                                </ListView.View>
                            </controls:SortableListView>
                            <controls:SortableListView Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding IngotAssets}"
                    ColumnHeaderArrowUpTemplate="{StaticResource HeaderTemplateArrowUp}" ColumnHeaderArrowDownTemplate="{StaticResource HeaderTemplateArrowDown}">
                                <ListView.View>
                                    <GridView>
                                        <controls:SortableGridViewColumn Width="44" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Width="32" Height="32" Source="{Binding Path=TextureFile, Converter={StaticResource DDSConverter}, ConverterParameter='32,32'}" SnapsToDevicePixels="True" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Ingots" Width="175" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding FriendlyName, Converter={StaticResource EnumToResouceConverter}}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Amount" Width="80" SortBinding="{Binding Amount}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Amount, StringFormat='{}{0:#,##0.00}'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Mass" Width="100" SortBinding="{Binding Mass}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Mass, StringFormat='{}{0:#,##0.00} Kg'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Volume" Width="90" SortBinding="{Binding Volume}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Volume, StringFormat='{}{0:#,##0.00} L'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Time" Width="90" SortBinding="{Binding Time}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Time, StringFormat='{}{0:hh\\:mm\\:ss\\.ff}'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                    </GridView>
                                </ListView.View>
                            </controls:SortableListView>
                            <controls:SortableListView Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding OreAssets}"
                    ColumnHeaderArrowUpTemplate="{StaticResource HeaderTemplateArrowUp}" ColumnHeaderArrowDownTemplate="{StaticResource HeaderTemplateArrowDown}">
                                <ListView.View>
                                    <GridView>
                                        <controls:SortableGridViewColumn Width="44" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Width="32" Height="32" Source="{Binding Path=TextureFile, Converter={StaticResource DDSConverter}, ConverterParameter='32,32'}" SnapsToDevicePixels="True" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Ore" Width="175" SortBinding="{Binding FriendlyName}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding FriendlyName, Converter={StaticResource EnumToResouceConverter}}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Amount" Width="80" SortBinding="{Binding Amount}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Amount, StringFormat='{}{0:#,##0.00}'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Mass" Width="100" SortBinding="{Binding Mass}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Mass, StringFormat='{}{0:#,##0.00} Kg'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                        <controls:SortableGridViewColumn Header="Volume" Width="90" SortBinding="{Binding Volume}">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Volume, StringFormat='{}{0:#,##0.00} L'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </controls:SortableGridViewColumn>
                                    </GridView>
                                </ListView.View>
                            </controls:SortableListView>
                        </Grid>
                    </ScrollViewer>
                    <controls:BusyIndicator Visibility="{Binding IsConstructionNotReady, Converter={StaticResource BooleanToVisibilityConverter}}" />
                </Grid>
            </TabItem>
        </TabControl>
        <controls:BusyIndicator Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}" />
    </Grid>
</UserControl>
